# Copyright (C) 2007-2015 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.

# GCC testsuite that uses the `dg.exp' driver.

# Exit immediately if this isn't a sh target.
if ![istarget sh*-*-*] then {
  return
}

# Load support procs.
load_lib gcc-dg.exp

# Return 1 if target is SH2A
proc check_effective_target_sh2a { } {
    return [check_no_compiler_messages sh2a object {
	     #ifndef __SH2A__
	     #error ""
	     #endif
    } ""]
}

# Return 1 if target is SH1
proc check_effective_target_sh1 { } {
    return [check_no_compiler_messages sh1 object {
	     #ifndef __SH1__
	     #error ""
	     #endif
    } ""]
}

# Return 1 if target supports atomic-model=soft-gusa
proc check_effective_target_atomic_model_soft_gusa_available { } {
    return [check_no_compiler_messages atomic_model_soft_gusa_available object {
	     int x = 0;
    } "-matomic-model=soft-gusa"]
}

# Return 1 if target supports atomic-model=soft-tcb
proc check_effective_target_atomic_model_soft_tcb_available { } {
    return [check_no_compiler_messages atomic_model_soft_tcb_available object {
	     int x = 0;
    } "-matomic-model=soft-tcb,gbr-offset=0"]
}

# Return 1 if target supports atomic-model=soft-imask
proc check_effective_target_atomic_model_soft_imask_available { } {
    return [check_no_compiler_messages atomic_model_soft_imask_available object {
	     int x = 0;
    } "-matomic-model=soft-imask -mno-usermode"]
}

# Return 1 if target supports atomic-model=hard-llcs
proc check_effective_target_atomic_model_hard_llcs_available { } {
    return [check_no_compiler_messages atomic_model_hard_llcs_available object {
	     int x = 0;
    } "-matomic-model=hard-llcs"]
}

# If a testcase doesn't have special options, use these.
global DEFAULT_CFLAGS
if ![info exists DEFAULT_CFLAGS] then {
    set DEFAULT_CFLAGS " -ansi -pedantic-errors"
}

# Initialize `dg'.
dg-init

# Main loop.
dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.\[cS\]]] \
	"" $DEFAULT_CFLAGS

# All done.
dg-finish
